layui.use(['table','form','jquery'], function(){
    var table = layui.table;
    var layer = layui.layer;
    var form = layui.form;
    var $ = layui.jquery;

    // 渲染dataType
    table.render({
        elem: '#deposit'
        ,url: ctx+'/eng/deposit/listPage'
        ,page: true
        ,cols: [[
            {field: 'id', title: 'ID',hide:true}
            ,{field: 'name', title: '暂存点名称', width:'15%',align:'center'}
            ,{field: 'code', title: '统一标识码', width:'15%',align:'center'}
            ,{field: 'address', title: '地址', width:'20%',align:'center'}
            ,{field: 'createTime', title: '创建时间', width:'15%',align:'center'}
            ,{field: 'createName', title: '创建人', width:'15%',align:'center'}
            ,{field: 'ops', title: '操作', width:'20%',align:'center',toolbar: '#tool'}
        ]],
        toolbar : '#toolbar',
        defaultToolbar :[],

    });


    table.on('tool(deposit)', function(obj){
        var data = obj.data;
        var layEvent = obj.event;

        if(layEvent === 'del'){

            // 确认是否需要删除数据
            layer.confirm('是否确定要删除?', {icon: 3, title:'提示'}, function(index){
                $.ajax({
                    url : ctx+"/eng/deposit/del",
                    data : {
                        id:data.id
                    },
                    success : function(res){
                        if(res.success){
                            layer.msg(res.msg,{icon:1})
                            table.reload('deposit');
                        }else{
                            layer.msg(res.msg,{icon:2})
                        }
                    }
                })
            });

        }
    });

    //toolbar
    table.on('toolbar(deposit)', function(obj){
        var event = obj.event;
        if(event == 'add'){
            layer.open({
                type : 1,
                content : $('#addWasteType')
            });
        }
    });

    form.on('submit(submitWasteType)',function(data){
        $.ajax({
            url : ctx+"/eng/deposit/add",
            data : data.field,
            type : 'post',
            async : false,
            success : function(res){
                if(res.success){
                    table.reload('deposit');
                    layer.closeAll();
                    layer.msg(res.msg,{icon:1});
                    $('#reset').click();
                }else{
                    layer.msg(res.msg,{icon:2})
                }
            }
        });
    })

});